package com.atguigu.yygh.msm.service.impl;

import com.atguigu.yygh.msm.service.MsmService;
import com.atguigu.yygh.msm.utils.HttpUtils;
import org.apache.http.HttpResponse;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName MsmServiceImpl
 * @Description 此类描述:
 * @Author dangchen
 * @DateTime 2022-10-15 16:04
 * @Version 1.0
 */
@Service
public class MsmServiceImpl implements MsmService {
    @Override
    public boolean send(String phone, String code) {
        String host = "http://dingxin.market.alicloudapi.com";
        String path = "/dx/sendSms";
        String method = "POST";
        String appcode = "91637593733c4dd0a572183162b14969";

        Map<String,String> headers = new HashMap<>();
        headers.put("Authorization","APPCODE"+appcode);
        Map<String,String> querys = new HashMap<>();
        querys.put("mobile",phone);
        querys.put("param","code:"+code);
        querys.put("tpl_id","TP1711063");
        Map<String,String> bodys = new HashMap<>();
        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            System.out.println(response.toString());
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
